package com.project.myPackage.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.project.myPackage.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

@Mapper
public interface OrdersMapper extends BaseMapper<Orders> {
    // 根据用户id获取所有订单信息,如果传入了status，则根据status获取订单信息 根据address_id关联地址表
    @Select("SELECT o.*, a.* " +
            "FROM orders o " +
            "LEFT JOIN address a ON o.address_id = a.address_id " +
            "WHERE o.user_id = #{user_id} AND o.status = #{status}")

    List<Map<String, Object>> getAllOrdersByUserId(Integer user_id,Integer status);


    //根据status获取订单信息 根据address_id关联地址表
    @Select("SELECT o.*, a.* " +
            "FROM orders o " +
            "LEFT JOIN address a ON o.address_id = a.address_id " +
            "WHERE o.status=#{status}"
           )

    List<Map<String, Object>> getAllOrdersByStatus(@Param("status") Integer status);
}
